package accel.connection;

import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.SocketAddress;

public class TCPConnector extends Connector {

	private static int port = 666;
	private Socket socket;
	private static volatile TCPConnector instance = null;
	private static String hostAddress ="";
	
	private TCPConnector() throws Exception
	{
		socket = new Socket();
		SocketAddress sockaddr = new InetSocketAddress(hostAddress, port);
		socket.connect(sockaddr, 4000);
		socket.setSoTimeout(4000);
		socket.setKeepAlive(true);
	}
	
	public synchronized static TCPConnector getInstance()
	{
		if (instance == null || instance.socket.isClosed())
		{
			try
			{
				instance = new TCPConnector();
			}
			catch(Exception e){return null;}
		}
		return instance;
	}
	
	public synchronized static TCPConnector resetInstance()
	{
		try
		{
			instance = new TCPConnector();
		}
		catch(Exception e)
		{
			instance = null;
		}
		return instance;
	}
	
}
